Skip to content

fix: write OpenAPI YAML atomically - #22

Merged
Arkptz merged 4 commits into
mainfrom
fix/atomic-output-write
Apr 22, 2026
Merged

fix: write OpenAPI YAML atomically#22
Arkptz merged 4 commits into
mainfrom
fix/atomic-output-write

Conversation

@Arkptz

@Arkptz Arkptz commented Apr 22, 2026

Copy link
Copy Markdown
Owner

Summary

Replace fs::write in write_yaml with an atomic temp-file + rename pattern using tempfile::NamedTempFile. On disk-full or permission-denied errors, the target file is left unchanged instead of being truncated to a broken partial write.

Type of Change

  • Bug fix (non-breaking)
  • New feature (non-breaking)
  • Breaking change (fix or feature that would cause existing behavior to change)
  • Documentation update
  • Refactoring / internal cleanup
  • CI / build / tooling

Checklist

  • cargo fmt --all clean
  • cargo clippy --all-targets --all-features -- -D warnings clean
  • cargo test passes locally
  • Added or updated tests for the change
  • Updated README / CLI help text if user-facing behavior changed
  • Added entry to CHANGELOG.md under [Unreleased] (if user-facing)
  • Used conventional commit style in commit messages (feat:, fix:, docs:, etc.)

Testing

  • cargo test --lib — 217 unit tests pass (including existing write_yaml tests)
  • cargo test --test output_atomic — 5 integration tests:
    • successful_write_creates_file — basic happy path
    • overwrite_existing_file — overwrites correctly
    • creates_parent_directories — nested dir creation
    • partial_write_preserves_target (Linux-only) — makes dir read-only, confirms original file survives failed write
    • write_to_nonexistent_parent_fails_gracefully — error on invalid path
  • cargo publish --dry-run passes

Related Issues

None

Arkptz added 4 commits April 22, 2026 23:50
On disk-full or permission-denied partway through the write, fs::write
leaves the target file truncated. Switch to NamedTempFile::new_in() +
write_all() + persist() so that the original file is never touched
until the full content is safely on disk.
Integration tests covering: successful write, overwrite, parent dir
creation, nonexistent parent error, and a Linux-only test that makes
the target directory read-only to confirm the original file survives.
Windows interprets paths without a drive letter as relative to the CWD,
so /nonexistent/dir/spec.yaml would succeed after create_dir_all and
invert the assertion. The test semantic is Unix-specific.
@Arkptz
Arkptz merged commit 9f94d6b into main Apr 22, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant